package cn.itcast.hotel.config;

import cn.itcast.hotel.constant.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Mq的配置类
 *
 * @author liudo
 * @version 1.0
 * @project hotel-demo
 * @date 2023/10/28 17:43:17
 */
@Configuration
public class MqConfiguration {

    @Bean
    public Queue hotelDeleteQueue() {
        return new Queue(MqConstants.HOTEL_DELETE_QUEUE);
    }

    @Bean
    public Queue hotelInsertQueue() {
        return new Queue(MqConstants.HOTEL_INSERT_QUEUE);
    }

    @Bean
    public TopicExchange hotelTopicExchange() {
        return new TopicExchange(MqConstants.HOTEL_EXCHANGE);
    }

    @Bean
    public Binding hotelTopicExchangeBindingHotelInsertQueue() {
        return BindingBuilder.bind(hotelInsertQueue())
                .to(hotelTopicExchange())
                .with(MqConstants.HOTEL_INSERT_KEY);
    }

    @Bean
    public Binding hotelTopicExchangeBindingHotelDeleteQueue() {
        return BindingBuilder.bind(hotelDeleteQueue())
                .to(hotelTopicExchange())
                .with(MqConstants.HOTEL_DELETE_KEY);
    }
}
